package communicationMessages;

import java.util.Map.Entry;
import java.util.logging.Level;

import logger.LoggerWriter;

import data.Forum;
import data.SubForum;
import data.ThreadMessage;

public class ViewSubForumMessage extends Message {

	@Override
	public String getAnswer() {
		LoggerWriter logger = LoggerWriter.getLoggerWriter();
		String ans="threadsList\n";
		String arr[] = this.content.split("\n");
		if (arr.length != 1)
		{
			logger.log("wrong format ViewSubForumMessage", Level.WARNING);
			ans = "wrong format ViewSubForumMessage";
			
		}
		else
		{
			SubForum tSubForum = Forum.getForum().getSubForum(Integer.valueOf(arr[0]));
			if (tSubForum == null)
			{
				logger.log("the number is " + arr[0] + "\n" + Integer.valueOf(arr[0]), Level.WARNING);
				ans = "wrong format ViewSubForumMessage";
				return ans;
			}
			for (Entry<Integer, ThreadMessage> tEntry : tSubForum.get_messages().entrySet()) {
				
				ans+=tEntry.getKey() + ":" + tEntry.getValue().get_title() + "\n";
			}
		}
		
		
		return ans;
	}

}
